const app = getApp()
Component({
  properties: {
    // defaultData（父页面传递的数据）
    defaultData: {
      type: Object,
      value: {
        title: "我是默认标题",
        showHome: false,
        showBack: true,
        showLogo: false,
        viewHeight: 0,
        is_share: "0",
        bgColor: '',
        goUrl: '',
        backType: 'white'
      },
      observer: function(newVal, oldVal) {}
    }
  },
  data: {
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    navBarHeight: app.globalData.navBarHeight,
    menuRight: app.globalData.menuRight,
    menuTop: app.globalData.menuTop,
    menuHeight: app.globalData.menuHeight
  },
  attached: function() {

  },
  methods: {

    goBack(e) {
      console.log(e)
      var url = e.currentTarget.dataset.url;
      var is_share = e.currentTarget.dataset.share;
      console.log("is_share:", is_share)
      if (is_share == "0" || is_share == undefined) {
        console.log("url:", url)
        if (url) {
          //判断回跳缓存是否有值
          var headerUrlList = wx.getStorageSync('headerUrlList');
          if (headerUrlList.constructor == Array && headerUrlList.length > 0) {
            //删除最后一个元素
            headerUrlList.splice(headerUrlList.length - 1, 1);
            wx.setStorageSync('headerUrlList', headerUrlList);
          }
          if (url == '/pages/square/index' || url == '/pages/my/index' || url == '/pages/index/index' || url == '/pages/brochure/index') {
            wx.switchTab({
              url: url
            })
          } else {
            wx.redirectTo({
              url: url
            });
          }
        } else {
          wx.navigateBack({
            delta: 1
          });
        }
      } else {
        wx.switchTab({
          url: '/pages/index/index',
        })
      }


    },
    goHome() {
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
  }
})